# Models for the Task application of Murphy TM
# Copyright (c) 2009 the murphy-tm team
#
# This file and all the other files belonging to the MurphyTM project
# are distributed under the terms of the GNU General Public License v3.
# See the COPYING file for details.

from django.db import models
from django.contrib.auth.models import User

import datetime

class TaskState(models.Model):
    """State of each task (e.g.: it is completed, suspended, being worked
    etc..)"""
    name = models.CharField(max_length = 50)

    def __unicode__(self):
        return self.name

class TaskCategory(models.Model):
    """Category of the task (e.g.: design, development, writing, etc..)"""
    name = models.CharField(max_length = 50)

    def __unicode__(self):
        return self.name

    class Meta:
        verbose_name_plural = "Task categories"

class Topic(models.Model):
    """Topic of projects"""
    name = models.CharField(max_length = 200)

    def __unicode__(self):
        return self.name

class Project(models.Model):
    """Project to which tasks can belong to"""
    name = models.CharField(max_length = 200)
    description = models.CharField(max_length = 200, blank = True, null = True)
    topic = models.ManyToManyField(Topic, blank = True, null = True)

    def __unicode__(self):
        return self.name

class Task(models.Model):
    """Class that represents a task, the core entity of this application"""
    # Most of the fields can be left blank in the Django admin, as we don't want to
    # make work heavier for the administrators

    # Of course, you need to insert at least the description of the task.
    description = models.CharField(max_length = 300)

    # And you need the ability of marking the task as completed or not
    completed = models.BooleanField(default = False)

    # Other fields, all optional.
    deadline = models.DateField(blank = True, null = True)
    state = models.ForeignKey(TaskState, blank = True, null = True)
    category = models.ForeignKey(TaskCategory, blank = True, null = True)
    assigned_by = models.ForeignKey(User, blank = True, null = True, related_name = "assigner")
    assigned_to = models.ForeignKey(User, blank = True, null = True, related_name = "assignee")
    project = models.ForeignKey(Project, blank = True, null = True)
    priority = models.IntegerField(blank = True, null = True)
    assignation_date = models.DateField(blank = True, null = True, default = datetime.datetime.now())

    def __unicode__(self):
        return self.description

